﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.XtraCharts;
using EventRegistration;


public partial class productStatistic_ReportForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CurrentData.RegistrationInfo.Completed) //If user not login, redirect to login page
            {
                Response.Redirect("../Register/Login.aspx");
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            #region Get data from database to a dataset
            string url = ConfigurationManager.ConnectionStrings["CocShopDatabaseConnectionString"].ToString();
            string sql = "SELECT b.Model, a.Quantity, a.StartDate FROM OrderScheduling a, Product b WHERE (a.ProductID = b.ProductID AND b.Model LIKE" +
            "'" + DropDownList1.SelectedValue + "')" + "GROUP BY a.OrderID, b.Model, a.Quantity, a.StartDate";
            SqlDataAdapter da = new SqlDataAdapter();
            SqlConnection con = new SqlConnection(url);
            da.SelectCommand = new SqlCommand(sql,con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            #endregion

            //Set datasource
            individualProductSqlDataSource.ConnectionString = url;
            individualProductWebChartControl.DataSourceID = null;
            individualProductWebChartControl.DataSource = ds;
            individualProductWebChartControl.DataAdapter = da;

            // Specify data members to bind the chart's series template.
            ChartTitle title = new ChartTitle();
            title.Text = "Product " + DropDownList1.SelectedValue + " Statistic By Orderdate";
            individualProductWebChartControl.Titles.Add(title);
            individualProductWebChartControl.SeriesDataMember = "Model";
            individualProductWebChartControl.SeriesTemplate.ArgumentDataMember = "StartDate";
            individualProductWebChartControl.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Quantity" });

            // Specify the template's series view.
            individualProductWebChartControl.SeriesTemplate.View = new LineSeriesView();
            individualProductWebChartControl.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.True;


        }
}

